package com.tanhua.server.contoller;

import com.tan.model.mongo.Movement;
import com.tan.model.vo.MovementsVo;
import com.tan.model.vo.PageResult;
import com.tan.model.vo.VisitorsVo;
import com.tanhua.server.service.CommentService;
import com.tanhua.server.service.Moventservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/movements")
public class MovenmentController {
    @Autowired
    Moventservice moventservice;
    @Autowired
    CommentService commentService;
    //发布动态
    @PostMapping
    public ResponseEntity publishMovement( Movement movement, MultipartFile[] imageContent) throws IOException {
        moventservice.publishMovement(movement,imageContent);
        return ResponseEntity.ok(null);
    }
    @GetMapping("/all")
    public ResponseEntity<PageResult> allMovements(@RequestParam(defaultValue = "1")Integer page,@RequestParam(defaultValue = "10")Integer pagesize,Long userId){
        PageResult pageResult= moventservice.allMovements(page,pagesize,userId);
         return ResponseEntity.ok(pageResult);
    }
    @GetMapping
    public ResponseEntity<PageResult> queryMovements(@RequestParam(defaultValue = "1")Integer page,@RequestParam(defaultValue = "10")Integer pagesize){
        PageResult pageResult= moventservice.FindfriendMovements(page,pagesize);
        return ResponseEntity.ok(pageResult);
    }
    @GetMapping("/recommend")
    public ResponseEntity<PageResult> queryRecommendMovements(@RequestParam(defaultValue = "1")Integer page,@RequestParam(defaultValue = "10")Integer pagesize){
        PageResult pageResult= moventservice.queryRecommendMovements(page,pagesize);
        return ResponseEntity.ok(pageResult);
    }
    @GetMapping("/{id}")
    public ResponseEntity<MovementsVo> getMovement(@PathVariable("id") String id){
        MovementsVo movementsVo= moventservice.getMovement(id);
        return ResponseEntity.ok(movementsVo);
    }
    @GetMapping("/{id}/like")
    public ResponseEntity<Integer> getLikeCount(@PathVariable("id") String Moventid){
        Integer count= moventservice.getLikeCount(Moventid);
        return ResponseEntity.ok(count);
    }
    @GetMapping("/{id}/dislike")
    public ResponseEntity<Integer> getdisLikeCount(@PathVariable("id") String Moventid){
        Integer count= moventservice.getdisLikeCount(Moventid);
        return ResponseEntity.ok(count);
    }
    @GetMapping("/{id}/love")
    public ResponseEntity<Integer> getLoveCount(@PathVariable("id") String Moventid){
        Integer count= moventservice.getLoveCount(Moventid);
        return ResponseEntity.ok(count);
    }
    @GetMapping("/{id}/unlove")
    public ResponseEntity<Integer> getdisLoveCount(@PathVariable("id") String Moventid){
        Integer count= moventservice.getdisLoveCount(Moventid);
        return ResponseEntity.ok(count);
    }
    /**
     * 谁看过我
     */
    @GetMapping("visitors")
    public ResponseEntity queryVisitorsList(){
        List<VisitorsVo> list = moventservice.queryVisitorsList();
        return ResponseEntity.ok(list);
    }
}
